home *** CD-ROM | disk | FTP | other *** search
/ Aminet 48 / Aminet 48 (2002)(GTI - Schatztruhe)[!][Apr 2002].iso / Aminet / text / edit / vim60rt.lha / Vim / vim60 / ftplugin / debchangelog.vim < prev    next >
Encoding:
Text File  |  2001-09-18  |  5.6 KB  |  185 lines

  1. " Vim filetype plugin file
  2. " Language:    Debian Changelog
  3. " Maintainer:    Michael Piefel <piefel@informatik.hu-berlin.de>
  4. " Last Change:    18 August 2001
  5.  
  6. if exists("g:did_changelog_ftplugin")
  7.   finish
  8. endif
  9.  
  10. " Don't load another plugin (this is global)
  11. let g:did_changelog_ftplugin = 1
  12.  
  13. " Helper functions returning various data.
  14. " Returns full name, either from $DEBFULLNAME or debianfullname.
  15. " TODO Is there a way to determine name from anywhere else?
  16. function <SID>FullName()
  17.     if exists("$DEBFULLNAME")
  18.     return $DEBFULLNAME
  19.     elseif exists("g:debianfullname")
  20.     return g:debianfullname
  21.     else
  22.     return "Your Name"
  23.     endif
  24. endfunction
  25.  
  26. " Returns email address, from $DEBEMAIL, $EMAIL or debianemail.
  27. function <SID>Email()
  28.     if exists("$DEBEMAIL")
  29.     return $DEBEMAIL
  30.     elseif exists("$EMAIL")
  31.     return $EMAIL
  32.     elseif exists("g:debianemail")
  33.     return g:debianfullemail
  34.     else
  35.     return "your@email.address"
  36.     endif
  37. endfunction
  38.  
  39. " Returns date in RFC822 format.
  40. function <SID>Date()
  41.     let savelang = v:lc_time
  42.     execute "language time C"
  43.     let dateandtime = strftime("%a, %d %b %Y %X %z")
  44.     execute "language time " . savelang
  45.     return dateandtime
  46. endfunction
  47.  
  48. function <SID>WarnIfNotUnfinalised()
  49.     if match(getline("."), " -- [[:alpha:]][[:alnum:].]")!=-1
  50.     echohl WarningMsg
  51.     echo "The entry has not been unfinalised before editing."
  52.     echohl None
  53.     return 1
  54.     endif
  55.     return 0
  56. endfunction
  57.  
  58. " These functions implement the menus
  59. function NewVersion()
  60.     " The new entry is unfinalised and shall be changed
  61.     amenu disable Changelog.New\ Version
  62.     amenu enable Changelog.Add\ Entry
  63.     amenu enable Changelog.Close\ Bug
  64.     amenu enable Changelog.Set\ Distribution
  65.     amenu enable Changelog.Set\ Urgency
  66.     amenu disable Changelog.Unfinalise
  67.     amenu enable Changelog.Finalise
  68.     call append(0, substitute(getline(1),'-\([[:digit:]]\+\))', '-Ü\1)', ''))
  69.     call append(1, "")
  70.     call append(2, "")
  71.     call append(3, " -- ")
  72.     call append(4, "")
  73.     call Distribution("unstable")
  74.     call Urgency("low")
  75.     normal 1G
  76.     call search(")")
  77.     normal h
  78.     normal 
  79.     call setline(1, substitute(getline(1),'-Ü\([[:digit:]]\+\))', '-\1)', ''))
  80.     call AddEntry()
  81. endfunction
  82.  
  83. function AddEntry()
  84.     normal 1G
  85.     call search("^ -- ")
  86.     normal kk
  87.     call append(".", "  * ")
  88.     normal jjj
  89.     let warn=<SID>WarnIfNotUnfinalised()
  90.     normal kk
  91.     if warn
  92.     echohl MoreMsg
  93.     call input("Hit ENTER")
  94.     echohl None
  95.     endif
  96.     startinsert!
  97. endfunction
  98.  
  99. function CloseBug()
  100.     normal 1G
  101.     call search("^ -- ")
  102.     let warn=<SID>WarnIfNotUnfinalised()
  103.     normal kk
  104.     call append(".", "  *  (closes: #" . input("Bug number to close: ") . ")")
  105.     normal j^ll
  106.     startinsert
  107. endfunction
  108.  
  109. function Distribution(dist)
  110.     call setline(1, substitute(getline(1), ") [[:lower:] ]*;", ") " . a:dist . ";", ""))
  111. endfunction
  112.  
  113. function Urgency(urg)
  114.     call setline(1, substitute(getline(1), "urgency=.*$", "urgency=" . a:urg, ""))
  115. endfunction
  116.  
  117. function Unfinalise()
  118.     " This means the entry shall be changed
  119.     amenu disable Changelog.New\ Version
  120.     amenu enable Changelog.Add\ Entry
  121.     amenu enable Changelog.Close\ Bug
  122.     amenu enable Changelog.Set\ Distribution
  123.     amenu enable Changelog.Set\ Urgency
  124.     amenu disable Changelog.Unfinalise
  125.     amenu enable Changelog.Finalise
  126.     normal 1G
  127.     call search("^ -- ")
  128.     call setline(".", " -- ")
  129. endfunction
  130.  
  131. function Finalise()
  132.     " This means the entry should not be changed anymore
  133.     amenu enable Changelog.New\ Version
  134.     amenu disable Changelog.Add\ Entry
  135.     amenu disable Changelog.Close\ Bug
  136.     amenu disable Changelog.Set\ Distribution
  137.     amenu disable Changelog.Set\ Urgency
  138.     amenu enable Changelog.Unfinalise
  139.     amenu disable Changelog.Finalise
  140.     normal 1G
  141.     call search("^ -- ")
  142.     call setline(".", " -- " . <SID>FullName() . " <" . <SID>Email() . ">  " . <SID>Date())
  143. endfunction
  144.  
  145.  
  146. function <SID>MakeMenu()
  147.     amenu &Changelog.&New\ Version            :call NewVersion()<CR>
  148.     amenu Changelog.&Add\ Entry                :call AddEntry()<CR>
  149.     amenu Changelog.&Close\ Bug                :call CloseBug()<CR>
  150.     menu Changelog.-sep-                <nul>
  151.  
  152.     amenu Changelog.Set\ &Distribution.&unstable    :call Distribution("unstable")<CR>
  153.     amenu Changelog.Set\ Distribution.&frozen        :call Distribution("frozen")<CR>
  154.     amenu Changelog.Set\ Distribution.&stable        :call Distribution("stable")<CR>
  155.     menu Changelog.Set\ Distribution.-sep-        <nul>
  156.     amenu Changelog.Set\ Distribution.frozen\ unstable    :call Distribution("frozen unstable")<CR>
  157.     amenu Changelog.Set\ Distribution.stable\ unstable    :call Distribution("stable unstable")<CR>
  158.     amenu Changelog.Set\ Distribution.stable\ frozen    :call Distribution("stable frozen")<CR>
  159.     amenu Changelog.Set\ Distribution.stable\ frozen\ unstable    :call Distribution("stable frozen unstable")<CR>
  160.  
  161.     amenu Changelog.Set\ &Urgency.&low            :call Urgency("low")<CR>
  162.     amenu Changelog.Set\ Urgency.&medium        :call Urgency("medium")<CR>
  163.     amenu Changelog.Set\ Urgency.&high            :call Urgency("high")<CR>
  164.  
  165.     menu Changelog.-sep-                <nul>
  166.     amenu Changelog.U&nfinalise                :call Unfinalise()<CR>
  167.     amenu Changelog.&Finalise                :call Finalise()<CR>
  168.     amenu Changelog.Finalise+Save            <nul>
  169.  
  170.     " Start off with a finalised entry
  171.     amenu disable Changelog.Add\ Entry
  172.     amenu disable Changelog.Close\ Bug
  173.     amenu disable Changelog.Set\ Distribution
  174.     amenu disable Changelog.Set\ Urgency
  175.     amenu disable Changelog.Finalise
  176.     amenu disable Changelog.Finalise+Save
  177. endfunction
  178.  
  179. augroup changelogMenu
  180. au BufEnter * if &filetype == "debchangelog" | call <SID>MakeMenu() | setlocal tw=78 | set comments=f:* | endif
  181. au BufLeave * if &filetype == "debchangelog" | aunmenu Changelog | endif
  182. augroup END
  183.  
  184.  
  185.